<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of newPHPClass
 *
 * @author G011C1102
 */
class LoginManager {

	public function __construct() {
		require_once './../php_class/DBManager.php';
		require_once './../php_class/Security.php';
	}

	public function loginChecker($name, $pass) {
		DBManager::init();
		$db = DBManager::$db;
		$stt = $db->prepare('SELECT password, salt FROM user WHERE account_id = :name');
		$stt->bindValue(':name', $name);
		$stt->execute();

		$q_pass = $stt->fetch();

		$boo = false;
		$sec = new Security();
		$sec_pass = $sec->salt_pass($pass, $q_pass['salt']);
		if ($this->checkPass($sec_pass, $q_pass['password'])) {
			session_start();
			$_SESSION['name'] = $name;
			
			$boo = true;
		}

		return $boo;
	}

	private function checkPass($pass, $q_pass) {
		if ($pass === $q_pass) {
			return true;
		}
		return false;
	}

}

?>
